package com.dong.builderMode.service;

import com.dong.builderMode.prepare.Matter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author DongJiaQi
 * @create 2022/12/20 14:55
 * @Description:
 */
public class DecorationPackageMenu implements IMenu {

    /**
     * 装修清单
     */
    private List<Matter> list = new ArrayList<Matter>();
    /**
     *  装修价格
     */
    private BigDecimal price = BigDecimal.ZERO;

    /**
     * ⾯积
     */
    private BigDecimal area;
    /**
     * 装修等级；豪华欧式、轻奢⽥园、现代简约
     */
    private String grade;
    private DecorationPackageMenu() {
    }

    public DecorationPackageMenu(Double area, String grade) {
        this.area = new BigDecimal(area);
        this.grade = grade;
    }

    @Override
    public IMenu appendCeiling(Matter matter) {
        addMatter(matter, "0.2");
        return this;
    }

    @Override
    public IMenu appendCoat(Matter matter) {
        addMatter(matter, "1.4");
        return this;
    }

    @Override
    public IMenu appendFloor(Matter matter) {
        addMatter(matter, "1");
        return this;
    }

    @Override
    public IMenu appendTile(Matter matter) {
        addMatter(matter, "1");
        return this;
    }

    @Override
    public String getDetail() {
        StringBuilder detail = new StringBuilder("\r\n-------------------------------------------------------\r\n" +
                "装修清单" + "\r\n" +
                        "套餐等级：" + grade + "\r\n" +
                        "套餐价格：" + price.setScale(2, BigDecimal.ROUND_HALF_UP) +
                        " 元\r\n" +
                        "房屋⾯积：" + area.doubleValue() + " 平⽶\r\n" +
                        "材料清单：\r\n");
        for (Matter matter: list) {
            detail.append(matter.scene()).append("：").append(matter.brand()).append("、").append(matter.model()).append("、平⽶价格：").append(matter.price()).append(" 元。\n");
        }
        return detail.toString();
    }
    private void addMatter(Matter matter, String val) {
        list.add(matter);
        price = price.add(area.multiply(new BigDecimal(val)).multiply(matter.price()));
    }
}
